package com.zmn.mcc.services.impl.staff.staffleaveoffice;

import com.zmn.mcc.model.entity.staff.staffleaveoffice.StaffLeaveOffice;
import com.zmn.mcc.model.entity.staff.staffleaveoffice.StaffLeaveOfficeQuery;
import com.zmn.mcc.persistence.interfaces.staff.staffleaveoffice.StaffLeaveOfficeDAO;
import com.zmn.mcc.services.interfaces.staff.StaffService;
import com.zmn.mcc.services.interfaces.staff.staffchangelog.StaffChangeLogService;
import com.zmn.mcc.services.interfaces.staff.staffleaveoffice.StaffLeaveOfficeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 离职信息表基础接口实现类
 *
 * @author tanghongjun
 * @since 2020-05-14 10:21:58
 **/
@Slf4j
@Service
public class StaffLeaveOfficeServiceImpl implements StaffLeaveOfficeService {

    private static final String TAG = "离职信息表基础服务接口";

    @Resource
    private StaffLeaveOfficeDAO staffLeaveOfficeDao;

    @Resource
    private StaffService staffService;

    @Resource
    private StaffChangeLogService staffChangeLogService;

    /**
     * 描述: 根据id查询数据
     *
     * @param leaveId id
     * @author tanghongjun
     * @since 2020-05-14 10:21:58
     **/
    @Override
    public StaffLeaveOffice findById(Integer leaveId) {

        if (Objects.isNull(leaveId)) {
            log.error("[{}],根据id查询数据leaveId为null", TAG);
            return null;
        }
        return staffLeaveOfficeDao.findById(leaveId);
    }

    @Override
    public StaffLeaveOffice findByStaffId(Integer staffId) {
        if (Objects.isNull(staffId)) {
            log.error("[{}],根据staffId查询数据为null", TAG);
            return null;
        }
        return staffLeaveOfficeDao.findByStaffId(staffId);
    }

    /**
     * 描述: 按条件查询数据 支持分页
     *
     * @param query 查询对象
     * @author tanghongjun
     * @since 2020-05-14 10:21:58
     **/
    @Override
    public List<StaffLeaveOffice> listPageByQuery(StaffLeaveOfficeQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return staffLeaveOfficeDao.listPageByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query 查询对象
     * @author tanghongjun
     * @since 2020-05-14 10:21:58
     **/
    @Override
    public List<StaffLeaveOffice> listByQuery(StaffLeaveOfficeQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return staffLeaveOfficeDao.listByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query 查询对象
     * @author tanghongjun
     * @since 2020-05-14 10:21:58
     **/
    @Override
    public Integer countByQuery(StaffLeaveOfficeQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return staffLeaveOfficeDao.countByQuery(query);
    }


    /**
     * 描述: 根据id修改数据 id为必传
     *
     * @param staffLeaveOffice 待修改数据
     * @return java.lang.Integer
     * @author tanghongjun
     * @since 2020-05-14 10:21:58
     **/
    @Override
    public Integer updateStaffLeaveOfficeByKey(StaffLeaveOffice staffLeaveOffice) {

        if (Objects.isNull(staffLeaveOffice.getLeaveId())) {
            log.error("[{}],根据id修改数据,staffLeaveOffice为null", TAG);
            return null;
        }
        return staffLeaveOfficeDao.updateStaffLeaveOfficeByKey(staffLeaveOffice);
    }

    /**
     * 描述: 新增数据
     *
     * @param staffLeaveOffice 待新增数据
     * @return java.lang.Integer 主键key
     * @author tanghongjun
     * @since 2020-05-14 10:21:58
     **/
    @Override
    public Integer insert(StaffLeaveOffice staffLeaveOffice) {

        if (Objects.isNull(staffLeaveOffice)) {
            log.error("[{}],新增数据,staffLeaveOffice为null", TAG);
            return null;
        }
        return staffLeaveOfficeDao.insert(staffLeaveOffice);
    }

    /**
     * 描述: 根据主键删除数据
     *
     * @param leaveId
     * @return: 执行结果码
     * @auther: tanghongjun
     * @since: 2020-05-14 10:21:58
     */
    @Override
    public Integer deleteByKey(Integer leaveId) {

        if (Objects.isNull(leaveId)) {
            log.error("[{}],根据id删除数据,leaveId为null", TAG);
            return null;
        }
        return staffLeaveOfficeDao.deleteByKey(leaveId);
    }

    @Override
    public Integer batchInsertByBs(List<StaffLeaveOffice> staffLeaveOfficeList) {

        return staffLeaveOfficeDao.batchInsertByBs(staffLeaveOfficeList);
    }

    @Override
    public Integer updateLeaveTime(StaffLeaveOffice staffLeaveOffice) {
        return staffLeaveOfficeDao.updateLeaveTime(staffLeaveOffice);
    }

}